<script type="text/html" template lay-done="layui.data.permanentUpdatedone(d);">
    <div class='permanent-updateHtml-content'>
        <div class="layui-card">
            <div class="layui-card-body" style="padding: 15px;">
                <form class="layui-form permanent-updateHtml-form" action="" lay-filter="permanent-updateHtml-form-group">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">任务名称</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-hide" name="id" value='{{d.params.id ? d.params.id : ""}}'>
                                <input type="text" value='{{d.params.taskname ? d.params.taskname : ""}}' name="taskname" lay-verify="taskname" autocomplete="off" placeholder="请输入标题" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">是否复核</label>
                            <div class="layui-input-inline"  style="width: 80px;">
                                <input {{ d.params.review && d.params.review === '1' ? "checked" : null}} type="checkbox" name="review" lay-skin="switch" lay-text="是|否">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">任务说明</label>
                        <div class="layui-input-block">
                            <textarea name="memo" placeholder="请输入内容" class="layui-textarea" style="min-height: 54px;">
                                    {{d.params.memo ? d.params.memo : ""}}
                            </textarea>
                        </div>
                    </div>  
                </form>
                <form class="layui-form permanent-frequency-form" action="" lay-filter="permanent-frequency-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">时间设置</label>
                        <div class="layui-input-block">
                            <div class="leftType">
                                <div class="topLeftType">
                                    <input type="radio" name="timeType" value="frequency" title="固定频率" lay-filter="timeType" {{ d.params.settype && d.params.settype === '0' ? "checked" : null}}>
                                </div>
                                <div class="bottomLeftType">
                                    <input type="radio" name="timeType" value="time" title="固定时间" lay-filter="timeType" {{ d.params.settype && d.params.settype === '1' ? "checked" : null}}>
                                </div>
                            </div>
                            <div class="frequencyType">
                                <div>
                                    <input type="radio" name="frequencyType" lay-filter="frequencyTimeType" value="year" title="每年" {{ d.params.hz && d.params.hz === 'year' ? "checked" : null}}>
                                </div>
                                <div>
                                    <input type="radio" name="frequencyType" lay-filter="frequencyTimeType" value="quarter" title="每季度" {{ d.params.hz && d.params.hz === 'quarter' ? "checked" : null}}>
                                </div>
                                <div>
                                    <input type="radio" name="frequencyType" lay-filter="frequencyTimeType" value="month" title="每月" {{ d.params.hz && d.params.hz === 'month' ? "checked" : null}}>
                                </div>
                                <div>
                                    <input type="radio" name="frequencyType" lay-filter="frequencyTimeType" value="week" title="每周" {{ d.params.hz && d.params.hz === 'week' ? "checked" : null}}>
                                </div>
                                <div>
                                    <input type="radio" name="frequencyType" lay-filter="frequencyTimeType" value="day" title="每日" {{ d.params.hz && d.params.hz === 'day' ? "checked" : null}}>
                                </div>
                            </div>
                            <div class="dateType" lay-filter="frequencyDateType">
                            </div>
                            <div class="listType">
                                <div class="header">
                                    最近5次填报时间
                                    <button type="button" style="float: right;" class="layui-btn layui-btn-sm T-event" data-target="viewlast">查看</button>
                                </div>
                                <div class="body"></div>
                            </div>
                        </div>
                    </div>
                </form>
                <div class="special-content">
                    <div class="special-key">
                        <button type="button" class="layui-btn layui-btn-xs" id="permanent-upload-filie"><i class="layui-icon"></i>上传文件</button>
                    </div>
                    <div class="special-value">
                        <div class="check-value-box permanent-update-files"></div>
                    </div>
                </div>
                <div class="special-content">
                    <div class="special-key">
                        <button type="button" class="layui-btn layui-btn-xs T-event" data-target="unit"><i class="layui-icon">&#xe608;</i>下发单位</button>
                    </div>
                    <div class="special-value">
                        <div class="check-value-box permanent-update-department">
                                {{#
                                    if(d.params.deptMsg || d.params.groupMsg) {
                                        var exitDep = d.params.deptMsg.length ? d.params.deptMsg : [],
                                            exGgrp = d.params.groupMsg.length ? d.params.groupMsg : [],
                                            allEx = exitDep.concat(exGgrp);
                                        layui.each(allEx, function(index,item) {
                                }}
                                    <div class="unit-content">
                                        {{item.dept_name}}
                                        <i class="layui-icon layui-icon-close T-event" data-target="delUnit" data-deptid="{{item.dept_id}}"></i>
                                    </div>
                                {{#
                                        })
                                    }
                                }}
                        </div>
                    </div>
                </div>
                <div class="iframeContent">
                    <iframe id="mainFormIframeInPermanent" class="permanent-updateHtml-form" src="./TheForm/main.html" frameborder="0"></iframe>
                </div>
                <div class="buttons-area">
                    <button type="button" class="T-event layui-btn" data-target="add">{{d.params.id ? '修改' : '创建'}}任务</button>
                </div>
            </div>
        </div>
    </div>
</script>
<style>
.permanent-updateHtml-content .layui-form-item .layui-inline {
    margin-right: 0px;
}
.permanent-updateHtml-content .special-content {
    width: 100%;
    margin-bottom: 15px;
}
.permanent-updateHtml-content .special-key {
    overflow: hidden;
    width: 80px;
    float: left;
    padding: 9px 15px;
    text-align: right;
}
.permanent-updateHtml-content .special-value {
    overflow: hidden;
    border: 1px solid #ccc;
    height: 50px;
}
.permanent-updateHtml-content .iframeContent {
    width: 100%;
    height: 520px;
    margin-bottom: 40px;
}

.permanent-updateHtml-content .iframeContent .permanent-updateHtml-form {
    width: 99%;
    height: 100%;
    overflow: auto;
}
.permanent-updateHtml-content .buttons-area {
    position: absolute;
    bottom: 0px;
    left: 0px;
    width: 100%;
    height: 40px;
    text-align: center;
    margin-top: 10px;
}
.permanent-updateHtml-content .check-value-box {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    padding: 2px 2px;
}
.permanent-updateHtml-content .unit-content {
    display: inline-block;
    padding: 2px 5px;
    padding-right: 15px;
    background-color: #ccc;
    position: relative;
    height: 20px;
    line-height: 20px;
}

.permanent-updateHtml-content .unit-content:hover i{
    visibility: visible;
    color: red;
    font-weight: 600;
}

.permanent-updateHtml-content .unit-content i {
    position: absolute;
    right: 0px;
    top: -2px;
    font-size: 14px;
    cursor: pointer;
    visibility: hidden;
}
.permanent-frequency-form .leftType {
    width: 120px;
    height: 170px;
    float: left;
    margin-right: 15px;
    border-right: 1px  solid #ccc;
}
.permanent-frequency-form .frequencyType {
    width: 95px;
    height: 170px;
    margin-right: 15px;
    float: left;
    border-right: 1px  solid #ccc;
}
.permanent-frequency-form .dateType {
    width: 400px;
    height: 170px;
    float: left;
    margin-right: 15px;
    border-right: 1px  solid #ccc;
}
.permanent-frequency-form .date-item {
    width: 100%;
    height: 32px;
    clear: both;
}
.permanent-frequency-form .date-item input {
    line-height: 32px;
}
.permanent-frequency-form .dateType .layui-form-mid {
    padding: 7px 0px !important;
}
.permanent-frequency-form .date-item .layui-input {
    height: 30px;
}
.permanent-frequency-form .listType {
    width: 300px;
    float: left;
    height: 170px;
}
.permanent-frequency-form .listType .header {
    height: 30px;
    text-align: center;
    line-height: 30px;
    font-size: 16px;
}
.permanent-frequency-form .listType .body {
    text-align: center;
}
</style>
<script type="text/html" id="permanentTimeItemTpl">
    {{# 
        var isFirst=d.isFirst;
    }}
    <div class="date-item">
        <div class="layui-input-inline" style="width: 150px;">
            <input type="text" name="starttime" value="{{d.data.starttime || ''}}" class="layui-input item-time item-time-start" data-timetype="start" placeholder="选择时间">
        </div>
        <div class="layui-form-mid">-</div>
        <div class="layui-input-inline" style="width: 150px;">
            <input type="text" name="endtime" value="{{d.data.endtime || ''}}" class="layui-input item-time item-time-end" data-timetype="end" placeholder="选择时间">
        </div>
        {{# if(!!isFirst) { }}
        <button type="button" class="layui-btn layui-btn-sm T-bEvent" data-target="addItem">
            <i class="layui-icon">&#xe654;</i>
        </button>
        {{# } else {  }}
        <button type="button" class="layui-btn layui-btn-sm T-bEvent" data-target="delItem">
            <i class="layui-icon">&#x1006;</i>
        </button>
        {{# } }}
    </div>
</script>
<script type="text/html" id="permanentselectunitTpl">
    {{#
        layui.each(d, function(index,item) {
    }}
        <div class="unit-content">
            {{item.dept_name}}
            <i class="layui-icon layui-icon-close T-event" data-target="delUnit" data-deptid="{{item.dept_id}}"></i>
        </div>
    {{#
        })
    }}
</script>
<script type="text/html" id="permanentShowLastTpl">
    {{#
        layui.each(d, function(index,item) {
    }}
        <p>开始：{{item.starttime}}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;结束：{{item.endtime}}</p>
    {{#
        })
    }}
</script>
<script type="text/html" id="permanentuploadFilesTpl">
    {{#
        layui.each(d, function(index,item) {
    }}
        <div class="unit-content">
            <a class="T-event" data-target="download" href="javascript: void(0);" data-url="{{item.url}}">{{item.filename}}</a>
            <i class="layui-icon layui-icon-close T-event" data-target="delFile" data-deptid="{{item.servername}}"></i>
        </div>
    {{#
        })
    }}
</script>
<script>
layui.data.permanentUpdatedone = function (d) { 
    layui.use(['admin', 'form', 'laydate', 'upload', 'tools'], function(){
        var $ = layui.$,
        admin = layui.admin,
        view = layui.view,
        element = layui.element,
        layer = layui.layer,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        upload = layui.upload,
        setter = layui.setter,
        tools = layui.tools,
        form = layui.form,
        filenames = [],
        timeInputType = 'year'; // year, quarter, month, week ,day
        
        form.render(null, 'permanent-updateHtml-form-group');
        form.render(null, 'permanent-frequency-form');

        var tempFileName = '';
        upload.render({
            elem: '#permanent-upload-filie',
            accept: 'file',
            url: 'myapi/DC/api/rest/web/custom/uploadfile',
            choose: function(obj) {
                obj.preview(function(index, file, result){
                    tempFileName = file.name;
                })
            },
            data: {
                access_token: layui.data(setter.tableName)[setter.request.tokenName]
            },
            done: function(res, index, upload){ //上传后的回调
                if(res.retcode === 1) {
                    filenames.push({filename: tempFileName, servername: res.servername});
                    var getTpl = permanentuploadFilesTpl.innerHTML;
                    var $tplC =$('.permanent-update-files');
                    laytpl(getTpl).render(filenames, function(html){
                        $tplC.html(html);
                    });
                }
            } 
            //,accept: 'file' //允许上传的文件类型
            //,size: 50 //最大允许上传的文件大小
            //,……
        });
        if(d.params.id) { //修改
            var timeDate = d.params.timeDate && d.params.timeDate.length && d.params.timeDate.length > 0 ? d.params.timeDate : [];
            if(timeDate.length > 0) {
                $.each(timeDate, function(index, item) {
                    item.starttime = moment(item.starttime).format('YYYY-MM-DD');
                    item.endtime = moment(item.endtime).format('YYYY-MM-DD');
                    insertDateTplByType(index === 0, item);
                })
            }else {
                insertDateTplByType(true);
            }
            var exitFileNames = d.params.fileNames;
            if(exitFileNames.length > 0) {
                filenames = exitFileNames;
                var Tplhtml = permanentuploadFilesTpl.innerHTML;
                var $tplF =$('.permanent-update-files');
                laytpl(Tplhtml).render(exitFileNames, function(html){
                    $tplF.html(html);
                });
            }
        }else { //新增
            insertDateTplByType(true);
        }
        
        //表单中时间频率类型改变事件
        form.on('radio(timeType)', function(data){
            var $form = $('.permanent-updateHtml-content .permanent-frequency-form');
            var timeTypeValue = data.value;
            if(timeTypeValue === 'frequency') {
                $form.find('.leftType input[name="timeType"][value="frequency"]').attr('checked', true);
                $form.find('.leftType input[name="timeType"][value="time"]').attr('checked', false);
                $form.find('.frequencyType input:radio').each(function(i, el) {
                    $(el).attr('disabled', false);
                    if(i===0) {
                        $(el).attr('checked', true);
                        $(el).click();
                    }
                });
                form.render('radio', 'permanent-frequency-form');
            }else if(timeTypeValue === 'time') {
                $form.find('.leftType input[name="timeType"][value="time"]').attr('checked', true);
                $form.find('.leftType input[name="timeType"][value="frequency"]').attr('checked', false);
                $form.find('.frequencyType input:radio').each(function(i, el) {
                    $(el).attr('disabled', true);
                })
                $form.find('input[name="frequencyType"]').removeAttr('checked');
                form.render('radio', 'permanent-frequency-form');
            }
            timeInputType = 'year';
            insertDateTplByType(true);
        });

        //表单中时间频率类型改变事件
        form.on('radio(frequencyTimeType)', function(data){
            var $form = $('.permanent-updateHtml-content .permanent-frequency-form');
            var frequencyTimeTypeValue = data.value;
            timeInputType = frequencyTimeTypeValue;
            insertDateTplByType(true);
        });

        //频率类型为频率时，根据时间来插入不同的时间选择组件
        function insertDateTplByType(isFirst,values) {
            var getTpl = permanentTimeItemTpl.innerHTML;
            var $tplC =$('.permanent-frequency-form .dateType');
            laytpl(getTpl).render({isFirst: isFirst, data: !!values ? values : {} }, function(html){
                var $ItemHtml = $(html);
                //给第一个时间行绑定时间组件
                bindTypeForItem($ItemHtml);
                !!isFirst ? $tplC.html($ItemHtml) : $tplC.append($ItemHtml);
                form.render(null, 'permanent-frequency-form');
            });
        }

        //给时间行绑定相应的时间操作
        function bindTypeForItem($ItemContariner, times) {
            $ItemContariner.each(function(index, el) {
                var commonMin = { year: 1900, month: 0, date: 1},
                    commonMax = { year: 2099, month: 11, date: 31};
                switch(timeInputType) {
                    case 'year':
                    var startDate = laydate.render({
                        elem: $ItemContariner.find('.item-time-start').get(0),
                        done: function (value, date) {
                            if(!!value) {
                                endDate.config.min = {
                                    year:date.year,
                                    month:date.month-1, 
                                    date: date.date,
                                };
                                endDate.config.max ={
                                    year: date.year+1,
                                    month:date.month-1, 
                                    date: date.date,
                                };
                            }else {
                                endDate.config.min = commonMin;
                                endDate.config.max = commonMax;
                            }
                        }
                    })
                    var endDate = laydate.render({
                        elem: $ItemContariner.find('.item-time-end').get(0),
                        done: function (value, date) {
                            if(!!value) {
                                startDate.config.min = {
                                    year: date.year-1,
                                    month: date.month - 1,
                                    date: date.date,
                                } 
                                startDate.config.max = {
                                    year: date.year,
                                    month: date.month - 1,
                                    date: date.date,
                                } 
                            }else {
                                startDate.config.min = commonMin;
                                startDate.config.max = commonMax; 
                            }
                        }
                    });
                    break;
                    case 'quarter':
                    var startDate = laydate.render({
                        elem: $ItemContariner.find('.item-time-start').get(0),
                        done: function (value, date) {
                            if(!!value) {
                                endDate.config.min = {
                                    year:date.year,
                                    month:date.month-1, 
                                    date: date.date,
                                };
                                var newDate = moment(value).add(3, 'M');
                                endDate.config.max ={
                                    year: newDate.year(),
                                    month: newDate.month(),
                                    date: newDate.date(),
                                };
                            }else {
                                endDate.config.min = commonMin;
                                endDate.config.max = commonMax;
                            }
                        }
                    })
                    var endDate = laydate.render({
                        elem: $ItemContariner.find('.item-time-end').get(0),
                        done: function (value, date) {
                            if(!!value) {
                                var newDate = moment(value).subtract(3, 'M');
                                startDate.config.min = {
                                    year: newDate.year(),
                                    month: newDate.month(),
                                    date: newDate.date(),
                                } 
                                startDate.config.max = {
                                    year: date.year,
                                    month: date.month - 1,
                                    date: date.date,
                                } 
                            }else {
                                startDate.config.min = commonMin;
                                startDate.config.max = commonMax; 
                            }
                        }
                    });
                    break;
                    case 'month':
                    var startDate = laydate.render({
                        elem: $ItemContariner.find('.item-time-start').get(0),
                        done: function (value, date) {
                            if(!!value) {
                                endDate.config.min = {
                                    year:date.year,
                                    month:date.month-1, 
                                    date: date.date,
                                };
                                var newDate = moment(value).add(1, 'M');
                                endDate.config.max ={
                                    year: newDate.year(),
                                    month: newDate.month(),
                                    date: newDate.date(),
                                };
                            }else {
                                endDate.config.min = commonMin;
                                endDate.config.max = commonMax;
                            }
                        }
                    })
                    var endDate = laydate.render({
                        elem: $ItemContariner.find('.item-time-end').get(0),
                        done: function (value, date) {
                            if(!!value) {
                                var newDate = moment(value).subtract(1, 'M');
                                startDate.config.min = {
                                    year: newDate.year(),
                                    month: newDate.month(),
                                    date: newDate.date(),
                                } 
                                startDate.config.max = {
                                    year: date.year,
                                    month: date.month - 1,
                                    date: date.date,
                                } 
                            }else {
                                startDate.config.min = commonMin;
                                startDate.config.max = commonMax; 
                            }
                        }
                    });
                    break;
                    case 'week':
                        var startDate = laydate.render({
                            elem: $ItemContariner.find('.item-time-start').get(0),
                            done: function (value, date) {
                                if(!!value) {
                                    endDate.config.min = {
                                        year:date.year,
                                        month:date.month-1, 
                                        date: date.date,
                                    };
                                    var newDate = moment(value).add(1, 'w');
                                    endDate.config.max ={
                                        year: newDate.year(),
                                        month: newDate.month(),
                                        date: newDate.date(),
                                    };
                                }else {
                                    endDate.config.min = commonMin;
                                    endDate.config.max = commonMax;
                                }
                            }
                        })
                        var endDate = laydate.render({
                            elem: $ItemContariner.find('.item-time-end').get(0),
                            done: function (value, date) {
                                if(!!value) {
                                    var newDate = moment(value).subtract(1, 'w');
                                    startDate.config.min = {
                                        year: newDate.year(),
                                        month: newDate.month(),
                                        date: newDate.date(),
                                    } 
                                    startDate.config.max = {
                                        year: date.year,
                                        month: date.month - 1,
                                        date: date.date,
                                    } 
                                }else {
                                    startDate.config.min = commonMin;
                                    startDate.config.max = commonMax; 
                                }
                            }
                        });
                    break;
                    case 'day':
                    var startDate = laydate.render({
                        elem: $ItemContariner.find('.item-time-start').get(0),
                        type: 'datetime',
                        format: 'yyyy-MM-dd HH',
                        done: function (value, date) {
                            if(!!value) {
                                endDate.config.min = {
                                    year:date.year,
                                    month:date.month-1, 
                                    date: date.date,
                                    hours: date.hours,
                                    minutes: 0,
                                    seconds: 0
                                };
                                var newDate = moment(value).add(1, 'd');
                                endDate.config.max ={
                                    year: newDate.year(),
                                    month: newDate.month(),
                                    date: newDate.date(),
                                    hours: newDate.hours(),
                                    minutes: 0,
                                    seconds: 0
                                };
                            }else {
                                endDate.config.min = commonMin;
                                endDate.config.max = commonMax;
                            }
                        }
                    })
                    var endDate = laydate.render({
                        elem: $ItemContariner.find('.item-time-end').get(0),
                        type: 'datetime',
                        format: 'yyyy-MM-dd HH',
                        done: function (value, date) {
                            if(!!value) {
                                var newDate = moment(value).subtract(1, 'd');
                                startDate.config.min = {
                                    year: newDate.year(),
                                    month: newDate.month(),
                                    date: newDate.date(),
                                    hours: newDate.hours(),
                                    minutes: 0,
                                    seconds: 0
                                } 
                                startDate.config.max = {
                                    year: date.year,
                                    month: date.month - 1,
                                    date: date.date,
                                    hours: date.hours,
                                    minutes: 0,
                                    seconds: 0
                                } 
                            }else {
                                startDate.config.min = commonMin;
                                startDate.config.max = commonMax; 
                            }
                        }
                    });
                    break;
                    default:
                    break;
                }
                
            })
        }

        var selectDep = d.params.deptMsg || [],
            selectGrp = d.params.groupMsg || [];
        window.selectTable = d.params.formMsg || [];

        //时间频率相关操作
        $('.permanent-updateHtml-content').on('click', '.T-bEvent', function() {
            var target = $(this).data('target');
            switch(target) {
                case 'addItem':
                    var itemLength = $(this).closest('.dateType').find('.date-item').length;
                    if(itemLength === 5) {
                        return false;
                    }
                    insertDateTplByType(false);
                break;
                case 'delItem':
                    var $item = $(this).closest('.date-item');
                    $item.remove();
                break;
                default:
                break;
            }
        })

        //页面按钮点击事件
        $('.permanent-updateHtml-content').on('click', '.T-event', function() {
            var $container = $('.permanent-updateHtml-content');
            var target = $(this).data('target');
            if(target === 'add') {
                var myIframe = document.getElementById('mainFormIframeInPermanent'),
                    iframeZtree = myIframe.contentWindow.iframeZtree,
                    checkTable = iframeZtree.getCheckedNodes(true),
                    formMsg = [];
                $.each(checkTable, function(index) {
                    if(!!checkTable[index].tablename) {
                        formMsg.push({form_id: checkTable[index].id})
                    }
                });
                var $form = $('.permanent-updateHtml-content .permanent-frequency-form');
                var arr = tools.getAreaArgs($form.find('.dateType .date-item'), {type: 'array'});
                var args = tools.getAreaArgs($('.permanent-updateHtml-form'), {input: 1});
                var hz = $form.find('input[name="frequencyType"]:checked').val();
                var settype = $form.find('input[name="timeType"]:checked').val() === 'frequency' ? 0 : 1;
                var timeDate = [];
                $.each(arr, function(index, item) {
                    item.starttime = moment(item.starttime).format('YYYY-MM-DD HH:mm:ss');
                    item.endtime = moment(item.endtime).format('YYYY-MM-DD HH:mm:ss');
                    item.hz = hz;
                    item.settype = settype;
                    timeDate.push(item);
                });
                args.fileNames = JSON.stringify(filenames);
                args.timeDate = JSON.stringify(timeDate);
                args.deptMsg = JSON.stringify(selectDep);
                args.groupMsg = JSON.stringify(selectGrp);
                args.formMsg = JSON.stringify(formMsg);
                args.model = 'insert';
                args.updatedata = '0';
                args.tasktype = 'cz';
                args.username = '';
                args.userid = '';
                args.filename = '';
                args.servername = '';
                args.deptname = '';
                args.deptid = '';
                if(!!d.params.id) {
                    args.model = 'update';
                    args.updatedata = '1';
                }
                admin.req({
                    url: 'myapi/DC/api/rest/web/custom/Resident',
                    type: 'post',
                    data: args,
                    success: function(res){
                        window.selectTable = [];
                        tools.destroyIframe(myIframe);
                        layer.closeAll('page');
                        d.params.callBack && d.params.callBack();
                    }
                });
            } else if (target === 'unit') {
                layer.open({
                    id: 'permanent-add-pastHtml',
                    title:'下发单位',
                    offset: '20px',
                    type: 1,
                    //skin: 'layui-layer-rim',
                    shadeClose: true,
                    area: ['600px', '650px'],
                    success: function(lay, index) {
                        view(this.id).render('./task/temporary/past', {
                            exitDep: selectDep,
                            exGgrp: selectGrp
                        }).done(function() {
                            $(lay).on('click', '.T-confirm', function() {
                                selectDep = JSON.parse($(lay).find('.data-dep-container').val());
                                selectGrp = JSON.parse($(lay).find('.data-group-container').val());
                                var depNameStr = selectDep.concat(selectGrp);
                                var getTpl = permanentselectunitTpl.innerHTML;
                                var $tplC =$('.permanent-update-department');
                                laytpl(getTpl).render(depNameStr, function(html){
                                    $tplC.html(html);
                                });
                                layer.close(index);
                            });
                        });
                    }
                });
            } else if (target === 'delUnit') {
                var depid = $(this).data('deptid');
                var filterDep = [];
                $.each(selectDep, function(index) {
                    if(selectDep[index].dept_id !== depid) {
                        filterDep.push(selectDep[index]);
                    }
                });
                selectDep = filterDep;
                var filterGrp = [];
                $.each(selectGrp, function(index) {
                    if(selectGrp[index].dept_id !== depid) {
                        filterGrp.push(selectGrp[index]);
                    }
                });
                selectGrp = filterGrp;
                var depNameStr = filterDep.concat(filterGrp);
                var getTpl = permanentselectunitTpl.innerHTML;
                var $tplC =$('.permanent-update-department');
                laytpl(getTpl).render(depNameStr, function(html){
                    $tplC.html(html);
                });
            } else if (target === 'delFile') {
                var depid = $(this).data('deptid');
                admin.req({
                    url: 'myapi/DC/api/rest/web/custom/Resident/delfile',
                    type: 'post',
                    data: {servername: depid},
                    success: function(res){
                        if(res.retcode == 0) {
                            var filterFiles = [];
                            $.each(filenames, function(index) {
                                if(filenames[index].servername !== depid) {
                                    filterFiles.push(filenames[index]);
                                }
                            });
                            filenames = filterFiles;
                            var getTpl = permanentuploadFilesTpl.innerHTML;
                            var $tplC =$('.permanent-update-files');
                            laytpl(getTpl).render(filenames, function(html){
                                $tplC.html(html);
                            });
                        }
                    }
                });
            } else if (target === 'viewlast') {
                var $form = $('.permanent-updateHtml-content .permanent-frequency-form');
                var arr = tools.getAreaArgs($form.find('.dateType .date-item'), {type: 'array'}, function($obj) {
                    var starttime = $obj.find('.item-time-start').val(),
                        endtime = $obj.find('.item-time-end').val();
                    return !!starttime && !!endtime;
                });
                var hz = $form.find('input[name="frequencyType"]').val();
                var timeDate = [];
                $.each(arr, function(index, item) {
                    item.starttime = moment(item.starttime).format('YYYY-MM-DD HH:mm:ss');
                    item.endtime = moment(item.endtime).format('YYYY-MM-DD HH:mm:ss');
                    timeDate.push(item);
                })
                var args = {
                    hz: hz,
                    timeDate: timeDate
                }
                if(timeDate.length === 0) {
                    layer.msg('请先选择至少一组开始结束时间');
                    return false;
                }
                admin.req({
                    url: 'myapi/DC/api/rest/web/custom/getthelatesttime',
                    type: 'post',
                    data: {time: JSON.stringify(args)},
                    success: function(res){
                        var getTpl = permanentShowLastTpl.innerHTML;
                        var $tplC =$('.permanent-frequency-form .listType .body');
                        laytpl(getTpl).render(res.data, function(html){
                            $tplC.html(html);
                        });
                    }
                });
            }else if (target === 'download') {
                var url = 'myapi/DC'+ $(this).data('url'),
                    name = $(this).text();
                tools.downMethodfunction(url, name);
            }
        })
    });
}

</script>